<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python基础语言 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>敌机发射子弹 | python基础语言</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../10day/section.16.html" />
    
    
    <link rel="prev" href="../10day/section.13.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="10.9"
        data-chapter-title="敌机发射子弹"
        data-filepath="10day/section.14.md"
        data-basepath=".."
        data-revision="Sat Aug 12 2017 10:09:16 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="03day/index.html">
            
                
                    <a href="../03day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        认识python和基础知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="linux/操作系统（科普章节）.html">
            
                
                    <a href="../linux/操作系统（科普章节）.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        操作系统（科普章节）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="03day/section.1.html">
            
                
                    <a href="../03day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        认识python(了解)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="03day/section.2.html">
            
                
                    <a href="../03day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第一个python程序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="03day/section.3.html">
            
                
                    <a href="../03day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        注释
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="03day/section.4.html">
            
                
                    <a href="../03day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        变量以及类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="03day/section.5.html">
            
                
                    <a href="../03day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        标示符和关键字
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="03day/section.6.html">
            
                
                    <a href="../03day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        输出
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="03day/section.4.1.html">
            
                
                    <a href="../03day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        输入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="03day/section.7.html">
            
                
                    <a href="../03day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.9.</b>
                        
                        运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="03day/section.10.html">
            
                
                    <a href="../03day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.10.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="04day/section.1.html">
            
                
                    <a href="../04day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.11.</b>
                        
                        判断语句介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="04day/section.2.html">
            
                
                    <a href="../04day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.12.</b>
                        
                        if语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="04day/section.3.html">
            
                
                    <a href="../04day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.13.</b>
                        
                        比较、关系运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="03day/section.99.html">
            
                
                    <a href="../03day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.14.</b>
                        
                        作业
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="03day/section.8.html">
            
                
                    <a href="../03day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.15.</b>
                        
                        附录-推荐的python电子书
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="04day/index.html">
            
                
                    <a href="../04day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        判断语句和循环语句
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="04day/section.4.html">
            
                
                    <a href="../04day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        if-else
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="04day/section.4.1.html">
            
                
                    <a href="../04day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        elif
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="04day/section.5.html">
            
                
                    <a href="../04day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        if嵌套
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="04day/section.6.html">
            
                
                    <a href="../04day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        if应用:猜拳游戏
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="04day/section.7.html">
            
                
                    <a href="../04day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        循环语句介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="04day/section.8.html">
            
                
                    <a href="../04day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        while循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="04day/section.8.1.html">
            
                
                    <a href="../04day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        while循环应用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="04day/section.10.html">
            
                
                    <a href="../04day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        break和continue
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="04day/section.9.html">
            
                
                    <a href="../04day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        while循环的嵌套以及应用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="04day/section.11.html">
            
                
                    <a href="../04day/section.11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        for循环
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="04day/section.12.html">
            
                
                    <a href="../04day/section.12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        总结
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="04day/section.99.html">
            
                
                    <a href="../04day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="05day/index.html">
            
                
                    <a href="../05day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        字符串、列表、元组、字典
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="05day/section.1.html">
            
                
                    <a href="../05day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        字符串介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="05day/section.2.html">
            
                
                    <a href="../05day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        字符串输出
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="05day/section.3.html">
            
                
                    <a href="../05day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        字符串输入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="05day/section.4.html">
            
                
                    <a href="../05day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        下标和切片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="05day/section.4.2.html">
            
                
                    <a href="../05day/section.4.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        字符串常见操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="05day/section.5.html">
            
                
                    <a href="../05day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        列表介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="05day/section.6.html">
            
                
                    <a href="../05day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        列表的循环遍历
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="05day/section.7.html">
            
                
                    <a href="../05day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        列表的常见操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="05day/section.8.html">
            
                
                    <a href="../05day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        列表的嵌套
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="06day/section.3.html">
            
                
                    <a href="../06day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="06day/section.1.html">
            
                
                    <a href="../06day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        字典介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="06day/section.2.html">
            
                
                    <a href="../06day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        字典的常见操作1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="06day/section.2.1.html">
            
                
                    <a href="../06day/section.2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        字典的常见操作2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="06day/section.2.2.html">
            
                
                    <a href="../06day/section.2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        字典的遍历
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.15" data-path="06day/section.2.3.html">
            
                
                    <a href="../06day/section.2.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.15.</b>
                        
                        公共方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.16" data-path="05day/section.99.html">
            
                
                    <a href="../05day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.16.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="06day/index.html">
            
                
                    <a href="../06day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        函数
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="07day/section.1.html">
            
                
                    <a href="../07day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        函数介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="07day/section.2.html">
            
                
                    <a href="../07day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        函数定义、调用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="07day/section.2.1.html">
            
                
                    <a href="../07day/section.2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        函数的文档说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="07day/section.3.html">
            
                
                    <a href="../07day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        函数参数(一)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="07day/section.4.html">
            
                
                    <a href="../07day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        函数返回值(一)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="07day/section.5.html">
            
                
                    <a href="../07day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        4种函数的类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="07day/section.6.html">
            
                
                    <a href="../07day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        函数的嵌套调用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="07day/section.6.1.html">
            
                
                    <a href="../07day/section.6.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        函数应用：打印图形和数学计算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="07day/section.7.0.html">
            
                
                    <a href="../07day/section.7.0.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        局部变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="07day/section.8.html">
            
                
                    <a href="../07day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        全局变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="07day/section.8.1.html">
            
                
                    <a href="../07day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        函数应用：学生管理系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="06day/section.4.1.html">
            
                
                    <a href="../06day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.12.</b>
                        
                        函数返回值(二)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="06day/section.3.1.html">
            
                
                    <a href="../06day/section.3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.13.</b>
                        
                        函数参数(二)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="06day/section.2.4.html">
            
                
                    <a href="../06day/section.2.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.14.</b>
                        
                        引用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.15" data-path="07day/section.9.html">
            
                
                    <a href="../07day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.15.</b>
                        
                        递归函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.16" data-path="07day/section.9.1.html">
            
                
                    <a href="../07day/section.9.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.16.</b>
                        
                        匿名函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.17" data-path="07day/section.7.html">
            
                
                    <a href="../07day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.17.</b>
                        
                        函数使用注意事项
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.18" data-path="07day/section.99.html">
            
                
                    <a href="../07day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.18.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="08day/index.html">
            
                
                    <a href="../08day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        文件操作、综合应用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="08day/section.1.html">
            
                
                    <a href="../08day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        文件操作介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="08day/section.2.html">
            
                
                    <a href="../08day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        文件的打开与关闭
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="08day/section.3.html">
            
                
                    <a href="../08day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        文件的读写
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="08day/section.3.1.html">
            
                
                    <a href="../08day/section.3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        应用1:制作文件的备份
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="08day/section.4.html">
            
                
                    <a href="../08day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        文件的定位读写
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="08day/section.5.html">
            
                
                    <a href="../08day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件、文件夹的相关操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="08day/section.9.html">
            
                
                    <a href="../08day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        应用2:批量修改文件名
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="08day/section.99.html">
            
                
                    <a href="../08day/section.99.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="09day/index.html">
            
                
                    <a href="../09day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        面向对象1
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="09day/section.1.html">
            
                
                    <a href="../09day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        面向对象编程介绍(1)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="09day/section.16.html">
            
                
                    <a href="../09day/section.16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        面向对象编程介绍(2)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="09day/section.2.html">
            
                
                    <a href="../09day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        类和对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="09day/section.3.html">
            
                
                    <a href="../09day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        定义类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="09day/section.4.html">
            
                
                    <a href="../09day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        创建对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="09day/section.5.1.html">
            
                
                    <a href="../09day/section.5.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        应用:创建多个对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="09day/section.4.1.html">
            
                
                    <a href="../09day/section.4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        self
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="09day/section.5.html">
            
                
                    <a href="../09day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        __init__方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.9" data-path="09day/section.4.4.html">
            
                
                    <a href="../09day/section.4.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.9.</b>
                        
                        &quot;魔法&quot;方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.10" data-path="09day/section.5.2.html">
            
                
                    <a href="../09day/section.5.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.10.</b>
                        
                        应用:烤地瓜
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.11" data-path="09day/section.5.4.html">
            
                
                    <a href="../09day/section.5.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.11.</b>
                        
                        隐藏数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.12" data-path="09day/section.5.3.html">
            
                
                    <a href="../09day/section.5.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.12.</b>
                        
                        应用:存放家具
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="10day/index.html">
            
                
                    <a href="../10day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        面向对象2
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="09day/section.4.3.html">
            
                
                    <a href="../09day/section.4.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        保护对象的属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="09day/section.6.html">
            
                
                    <a href="../09day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        __del__方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="09day/section.7.html">
            
                
                    <a href="../09day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        单继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="09day/section.8.html">
            
                
                    <a href="../09day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        多继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="09day/section.8.1.html">
            
                
                    <a href="../09day/section.8.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        重写父类方法与调用父类方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="09day/section.9.html">
            
                
                    <a href="../09day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        多态
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="09day/section.9.1.html">
            
                
                    <a href="../09day/section.9.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        类属性、实例属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.8" data-path="09day/section.10.html">
            
                
                    <a href="../09day/section.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.8.</b>
                        
                        静态方法和类方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="11day/index.html">
            
                
                    <a href="../11day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        面向对象3、异常、模块
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="11day/section.4.html">
            
                
                    <a href="../11day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        __new__方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="09day/section.13.html">
            
                
                    <a href="../09day/section.13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        单例模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="10day/section.1.html">
            
                
                    <a href="../10day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        异常介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="10day/section.2.html">
            
                
                    <a href="../10day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        捕获异常
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="10day/section.2.2.html">
            
                
                    <a href="../10day/section.2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        异常的传递
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="10day/section.3.html">
            
                
                    <a href="../10day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        抛出自定义的异常
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="10day/section.3.2.html">
            
                
                    <a href="../10day/section.3.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        异常处理中抛出异常
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.8" data-path="08day/section.7.html">
            
                
                    <a href="../08day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.8.</b>
                        
                        模块介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.9" data-path="08day/section.8.html">
            
                
                    <a href="../08day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.9.</b>
                        
                        模块制作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.10" data-path="08day/section.8.3.html">
            
                
                    <a href="../08day/section.8.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.10.</b>
                        
                        模块中的__all__
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.11" data-path="08day/section.7.1.html">
            
                
                    <a href="../08day/section.7.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.11.</b>
                        
                        python中的包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.12" data-path="08day/section.8.4.html">
            
                
                    <a href="../08day/section.8.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.12.</b>
                        
                        使用pip来安装模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="12day/index.html">
            
                
                    <a href="../12day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        强化练习
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="09day/section.12.html">
            
                
                    <a href="../09day/section.12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        应用:反恐精英
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="12day/section.3.html">
            
                
                    <a href="../12day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        给程序传参数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="12day/section.4.html">
            
                
                    <a href="../12day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        列表推导式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="12day/section.5.html">
            
                
                    <a href="../12day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.4.</b>
                        
                        set、list、tuple
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="07day/index.html">
            
                
                    <a href="../07day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        应用:飞机大战
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="10day/section.5.html">
            
                
                    <a href="../10day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        搭建界面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="10day/section.6.html">
            
                
                    <a href="../10day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        检测键盘
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="10day/section.7.html">
            
                
                    <a href="../10day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                        显示、控制玩具飞机-面向过程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="10day/section.8.html">
            
                
                    <a href="../10day/section.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.4.</b>
                        
                        显示、控制玩具飞机-面向对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="10day/section.9.html">
            
                
                    <a href="../10day/section.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.5.</b>
                        
                        玩家飞机发射子弹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="10day/section.12.html">
            
                
                    <a href="../10day/section.12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.6.</b>
                        
                        显示敌机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.7" data-path="10day/section.11.html">
            
                
                    <a href="../10day/section.11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.7.</b>
                        
                        优化代码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.8" data-path="10day/section.13.html">
            
                
                    <a href="../10day/section.13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.8.</b>
                        
                        让敌机移动
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="10.9" data-path="10day/section.14.html">
            
                
                    <a href="../10day/section.14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.9.</b>
                        
                        敌机发射子弹
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.10" data-path="10day/section.16.html">
            
                
                    <a href="../10day/section.16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.10.</b>
                        
                        代码优化-抽象出基类
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python基础语言</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x6253;&#x98DE;&#x673A;&#x4EE3;&#x7801;&#xFF1A;&#x654C;&#x673A;&#x53D1;&#x5C04;&#x5B50;&#x5F39;">&#x6253;&#x98DE;&#x673A;&#x4EE3;&#x7801;&#xFF1A;&#x654C;&#x673A;&#x53D1;&#x5C04;&#x5B50;&#x5F39;</h1>
<p><img src="../Images/&#x9879;&#x76EE;&#x622A;&#x56FE;-10py-1.png" alt=""></p>
<p><img src="../Images/&#x9879;&#x76EE;&#x622A;&#x56FE;-10py-2.png" alt=""></p>
<p><img src="../Images/&#x9879;&#x76EE;&#x622A;&#x56FE;-11py.png" alt=""></p>
<pre><code class="lang-python"><span class="hljs-comment">#coding=utf-8</span>
<span class="hljs-keyword">import</span> pygame
<span class="hljs-keyword">from</span> pygame.locals <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> random

<span class="hljs-string">&apos;&apos;&apos;
    9. &#x8BA9;&#x654C;&#x673A;&#x53D1;&#x5C04;&#x5B50;&#x5F39;
&apos;&apos;&apos;</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HeroPlane</span><span class="hljs-params">(object)</span>:</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,screen)</span>:</span>

        <span class="hljs-comment">#&#x8BBE;&#x7F6E;&#x98DE;&#x673A;&#x9ED8;&#x8BA4;&#x7684;&#x4F4D;&#x7F6E;</span>
        self.x = <span class="hljs-number">230</span>
        self.y = <span class="hljs-number">700</span>

        <span class="hljs-comment">#&#x8BBE;&#x7F6E;&#x8981;&#x663E;&#x793A;&#x5185;&#x5BB9;&#x7684;&#x7A97;&#x53E3;</span>
        self.screen = screen

        self.imageName = <span class="hljs-string">&quot;./feiji/hero1.png&quot;</span>
        self.image = pygame.image.load(self.imageName).convert()

        <span class="hljs-comment">#&#x7528;&#x6765;&#x5B58;&#x50A8;&#x82F1;&#x96C4;&#x98DE;&#x673A;&#x53D1;&#x5C04;&#x7684;&#x6240;&#x6709;&#x5B50;&#x5F39;</span>
        self.bulletList = []

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">display</span><span class="hljs-params">(self)</span>:</span>
        self.screen.blit(self.image,(self.x,self.y))

        <span class="hljs-comment">#&#x5224;&#x65AD;&#x4E00;&#x4E0B;&#x5B50;&#x5F39;&#x7684;&#x4F4D;&#x7F6E;&#x662F;&#x5426;&#x8D8A;&#x754C;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x8981;&#x5220;&#x9664;&#x8FD9;&#x9897;&#x5B50;&#x5F39;</span>
        <span class="hljs-comment">#</span>
        <span class="hljs-comment">#&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x4F1A;&#x6F0F;&#x6389;&#x5F88;&#x591A;&#x9700;&#x8981;&#x5220;&#x9664;&#x7684;&#x6570;&#x636E;</span>
        <span class="hljs-comment"># for i in self.bulletList:</span>
        <span class="hljs-comment">#     if i.y&lt;0:</span>
        <span class="hljs-comment">#         self.bulletList.remove(i)</span>

        <span class="hljs-comment">#&#x7528;&#x6765;&#x5B58;&#x653E;&#x9700;&#x8981;&#x5220;&#x9664;&#x7684;&#x5BF9;&#x8C61;&#x5F15;&#x7528;</span>
        needDelItemList = []

        <span class="hljs-comment">#&#x4FDD;&#x5B58;&#x9700;&#x8981;&#x5220;&#x9664;&#x7684;&#x5BF9;&#x8C61;</span>
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> self.bulletList:
            <span class="hljs-keyword">if</span> i.judge():
                needDelItemList.append(i)

        <span class="hljs-comment">#&#x5220;&#x9664;self.bulletList&#x4E2D;&#x9700;&#x8981;&#x5220;&#x9664;&#x7684;&#x5BF9;&#x8C61;</span>
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> needDelItemList:
            self.bulletList.remove(i)

        <span class="hljs-comment">#&#x56E0;&#x4E3A;needDelItemList&#x4E5F;&#x4FDD;&#x5B58;&#x4E86;&#x521A;&#x521A;&#x5220;&#x9664;&#x7684;&#x5BF9;&#x8C61;&#x7684;&#x5F15;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x5220;&#x9664;&#x6574;&#x4E2A;&#x5217;&#x8868;&#xFF0C;&#x90A3;&#x4E48;</span>
        <span class="hljs-comment">#&#x6574;&#x4E2A;&#x5217;&#x8868;&#x4E2D;&#x7684;&#x5F15;&#x7528;&#x5C31;&#x4E0D;&#x5B58;&#x5728;&#x4E86;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4E0D;&#x8C03;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x56E0;&#x4E3A;needDelItemList&#x662F;&#x5C40;&#x90E8;&#x53D8;&#x91CF;</span>
        <span class="hljs-comment">#&#x5F53;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528;&#x7ED3;&#x675F;&#x65F6;&#xFF0C;&#x8FD9;&#x4E2A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x4E5F;&#x5C31;&#x4E0D;&#x5B58;&#x5728;&#x4E86;</span>
        <span class="hljs-comment"># del needDelItemList</span>

        <span class="hljs-keyword">for</span> bullet <span class="hljs-keyword">in</span> self.bulletList:
            bullet.display()<span class="hljs-comment">#&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x5B50;&#x5F39;&#x7684;&#x4F4D;&#x7F6E;</span>
            bullet.move()<span class="hljs-comment">#&#x8BA9;&#x8FD9;&#x4E2A;&#x5B50;&#x5F39;&#x8FDB;&#x884C;&#x79FB;&#x52A8;&#xFF0C;&#x4E0B;&#x6B21;&#x518D;&#x663E;&#x793A;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x770B;&#x5230;&#x5B50;&#x5F39;&#x5728;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x4F4D;&#x7F6E;</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">moveLeft</span><span class="hljs-params">(self)</span>:</span>
        self.x -= <span class="hljs-number">10</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">moveRight</span><span class="hljs-params">(self)</span>:</span>
        self.x += <span class="hljs-number">10</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sheBullet</span><span class="hljs-params">(self)</span>:</span>
        newBullet = Bullet(self.x, self.y, self.screen)
        self.bulletList.append(newBullet)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bullet</span><span class="hljs-params">(object)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,x,y,screen)</span>:</span>
        self.x = x+<span class="hljs-number">40</span>
        self.y = y-<span class="hljs-number">20</span>
        self.screen = screen
        self.image = pygame.image.load(<span class="hljs-string">&quot;./feiji/bullet.png&quot;</span>).convert()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">move</span><span class="hljs-params">(self)</span>:</span>
        self.y -= <span class="hljs-number">5</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">display</span><span class="hljs-params">(self)</span>:</span>
        self.screen.blit(self.image,(self.x,self.y))

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">judge</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">if</span> self.y&lt;<span class="hljs-number">0</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">True</span>
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">False</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EnemyPlane</span><span class="hljs-params">(object)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,screen)</span>:</span>
        <span class="hljs-comment">#&#x8BBE;&#x7F6E;&#x98DE;&#x673A;&#x9ED8;&#x8BA4;&#x7684;&#x4F4D;&#x7F6E;</span>
        self.x = <span class="hljs-number">0</span>
        self.y = <span class="hljs-number">0</span>

        <span class="hljs-comment">#&#x8BBE;&#x7F6E;&#x8981;&#x663E;&#x793A;&#x5185;&#x5BB9;&#x7684;&#x7A97;&#x53E3;</span>
        self.screen = screen

        self.imageName = <span class="hljs-string">&quot;./feiji/enemy0.png&quot;</span>
        self.image = pygame.image.load(self.imageName).convert()

        self.direction = <span class="hljs-string">&quot;right&quot;</span>

        <span class="hljs-comment">#&#x7528;&#x6765;&#x5B58;&#x50A8;&#x654C;&#x4EBA;&#x98DE;&#x673A;&#x53D1;&#x5C04;&#x7684;&#x6240;&#x6709;&#x5B50;&#x5F39;</span>
        self.bulletList = []

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">display</span><span class="hljs-params">(self)</span>:</span>
        self.screen.blit(self.image,(self.x,self.y))
        <span class="hljs-comment">#&#x5224;&#x65AD;&#x4E00;&#x4E0B;&#x5B50;&#x5F39;&#x7684;&#x4F4D;&#x7F6E;&#x662F;&#x5426;&#x8D8A;&#x754C;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x8981;&#x5220;&#x9664;&#x8FD9;&#x9897;&#x5B50;&#x5F39;</span>
        <span class="hljs-comment">#</span>
        <span class="hljs-comment">#&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x4F1A;&#x6F0F;&#x6389;&#x5F88;&#x591A;&#x9700;&#x8981;&#x5220;&#x9664;&#x7684;&#x6570;&#x636E;</span>
        <span class="hljs-comment"># for i in self.bulletList:</span>
        <span class="hljs-comment">#     if i.y&lt;0:</span>
        <span class="hljs-comment">#         self.bulletList.remove(i)</span>

        <span class="hljs-comment">#&#x5B58;&#x653E;&#x9700;&#x8981;&#x5220;&#x9664;&#x7684;&#x5BF9;&#x8C61;&#x4FE1;&#x606F;</span>
        needDelItemList = []

        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> self.bulletList:
            <span class="hljs-keyword">if</span> i.judge():
                needDelItemList.append(i)
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> needDelItemList:
            self.bulletList.remove(i)

        <span class="hljs-comment"># del needDelItemList</span>

        <span class="hljs-comment">#&#x66F4;&#x65B0;&#x53CA;&#x8FD9;&#x67B6;&#x98DE;&#x673A;&#x53D1;&#x5C04;&#x51FA;&#x7684;&#x6240;&#x6709;&#x5B50;&#x5F39;&#x7684;&#x4F4D;&#x7F6E;</span>
        <span class="hljs-keyword">for</span> bullet <span class="hljs-keyword">in</span> self.bulletList:
            bullet.display()
            bullet.move()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">move</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-comment">#&#x5982;&#x679C;&#x78B0;&#x5230;&#x4E86;&#x53F3;&#x8FB9;&#x7684;&#x8FB9;&#x754C;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x5F80;&#x5DE6;&#x8D70;&#xFF0C;&#x5982;&#x679C;&#x78B0;&#x5230;&#x4E86;&#x5DE6;&#x8FB9;&#x7684;&#x8FB9;&#x754C;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x5F80;&#x53F3;&#x8D70;</span>
        <span class="hljs-keyword">if</span> self.direction == <span class="hljs-string">&quot;right&quot;</span>:
            self.x += <span class="hljs-number">4</span>
        <span class="hljs-keyword">elif</span> self.direction == <span class="hljs-string">&quot;left&quot;</span>:
            self.x -= <span class="hljs-number">4</span>

        <span class="hljs-keyword">if</span> self.x&gt;<span class="hljs-number">480</span>-<span class="hljs-number">50</span>:
            self.direction = <span class="hljs-string">&quot;left&quot;</span>
        <span class="hljs-keyword">elif</span> self.x&lt;<span class="hljs-number">0</span>:
            self.direction = <span class="hljs-string">&quot;right&quot;</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sheBullet</span><span class="hljs-params">(self)</span>:</span>
        num = random.randint(<span class="hljs-number">1</span>,<span class="hljs-number">100</span>)
        <span class="hljs-keyword">if</span> num == <span class="hljs-number">88</span>:
            newBullet = EnemyBullet(self.x,self.y,self.screen)
            self.bulletList.append(newBullet)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EnemyBullet</span><span class="hljs-params">(object)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,x,y,screen)</span>:</span>
        self.x = x+<span class="hljs-number">30</span>
        self.y = y+<span class="hljs-number">30</span>
        self.screen = screen
        self.image = pygame.image.load(<span class="hljs-string">&quot;./feiji/bullet1.png&quot;</span>).convert()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">move</span><span class="hljs-params">(self)</span>:</span>
        self.y += <span class="hljs-number">4</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">display</span><span class="hljs-params">(self)</span>:</span>
        self.screen.blit(self.image,(self.x,self.y))

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">judge</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">if</span> self.y&gt;<span class="hljs-number">852</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">True</span>
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">False</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">key_control</span><span class="hljs-params">(heroPlane)</span>:</span>
    <span class="hljs-comment">#&#x5224;&#x65AD;&#x662F;&#x5426;&#x662F;&#x70B9;&#x51FB;&#x4E86;&#x9000;&#x51FA;&#x6309;&#x94AE;</span>
    <span class="hljs-keyword">for</span> event <span class="hljs-keyword">in</span> pygame.event.get():
        <span class="hljs-comment"># print(event.type)</span>
        <span class="hljs-keyword">if</span> event.type == QUIT:
            print(<span class="hljs-string">&quot;exit&quot;</span>)
            exit()
        <span class="hljs-keyword">elif</span> event.type == KEYDOWN:
            <span class="hljs-keyword">if</span> event.key == K_a <span class="hljs-keyword">or</span> event.key == K_LEFT:
                print(<span class="hljs-string">&apos;left&apos;</span>)
                heroPlane.moveLeft()
                <span class="hljs-comment">#&#x63A7;&#x5236;&#x98DE;&#x673A;&#x8BA9;&#x5176;&#x5411;&#x5DE6;&#x79FB;&#x52A8;</span>
            <span class="hljs-keyword">elif</span> event.key == K_d <span class="hljs-keyword">or</span> event.key == K_RIGHT:
                print(<span class="hljs-string">&apos;right&apos;</span>)
                heroPlane.moveRight()
            <span class="hljs-keyword">elif</span> event.key == K_SPACE:
                print(<span class="hljs-string">&apos;space&apos;</span>)
                heroPlane.sheBullet()

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment">#1. &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A97;&#x53E3;&#xFF0C;&#x7528;&#x6765;&#x663E;&#x793A;&#x5185;&#x5BB9;</span>
    screen = pygame.display.set_mode((<span class="hljs-number">480</span>,<span class="hljs-number">852</span>),<span class="hljs-number">0</span>,<span class="hljs-number">32</span>)

    <span class="hljs-comment">#2. &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x548C;&#x7A97;&#x53E3;&#x5927;&#x5C0F;&#x7684;&#x56FE;&#x7247;&#xFF0C;&#x7528;&#x6765;&#x5145;&#x5F53;&#x80CC;&#x666F;</span>
    background = pygame.image.load(<span class="hljs-string">&quot;./feiji/background.png&quot;</span>).convert()

    <span class="hljs-comment">#3.1 &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x98DE;&#x673A;&#x5BF9;&#x8C61;</span>
    heroPlane = HeroPlane(screen)
    <span class="hljs-comment">#3.2 &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x654C;&#x4EBA;&#x98DE;&#x673A;</span>
    enemyPlane = EnemyPlane(screen)

    <span class="hljs-comment">#4. &#x628A;&#x80CC;&#x666F;&#x56FE;&#x7247;&#x653E;&#x5230;&#x7A97;&#x53E3;&#x4E2D;&#x663E;&#x793A;</span>
    <span class="hljs-keyword">while</span> <span class="hljs-keyword">True</span>:
        screen.blit(background,(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>))

        heroPlane.display()

        enemyPlane.move()
        enemyPlane.display()
        enemyPlane.sheBullet()

        key_control(heroPlane)

        pygame.display.update()

        <span class="hljs-comment">#&#x901A;&#x8FC7;&#x5EF6;&#x65F6;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x6765;&#x964D;&#x4F4E;&#x8FD9;&#x4E2A;while&#x5FAA;&#x73AF;&#x7684;&#x5FAA;&#x73AF;&#x901F;&#x5EA6;&#xFF0C;&#x4ECE;&#x800C;&#x964D;&#x4F4E;&#x4E86;cpu&#x5360;&#x7528;&#x7387;</span>
        time.sleep(<span class="hljs-number">0.01</span>)

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
    main()
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../10day/section.13.html" class="navigation navigation-prev " aria-label="Previous page: 让敌机移动"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../10day/section.16.html" class="navigation navigation-next " aria-label="Next page: 代码优化-抽象出基类"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python基础语言 -->
</html>
